#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int m, n,k=0,i=0,f=0;
	cout << " input the number of n and m: ";
	cin >> n >> m;
	 vector<bool> a(n+1,1);
	 do
	 {
		 ++i;
		 if (i> n)
			 i = 1;
		 if (a[i])
			 k++;
		 if (k == m)
		 {
			 k = 0;
			/* cout << i << ' ';*/
			 a[i] = 0;
			 f++;                       //death number
		 }
	 } while (f != n);
	 cout << i;
	return 0;
}